import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JButton;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;


public class BenchMarkingSorting {

	private JFrame frame;
	private JTextField textField;
	private JTextField textField_1;
	private JTextField textField_2;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					BenchMarkingSorting window = new BenchMarkingSorting();
					window.frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the application.
	 */
	public BenchMarkingSorting() {
		initialize();
	}

	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {
		frame = new JFrame();
		frame.setBounds(100, 100, 490, 339);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.getContentPane().setLayout(null);
		
		JLabel lblEnterNumbers = new JLabel("Enter Numbers");
		lblEnterNumbers.setBounds(30, 39, 76, 22);
		frame.getContentPane().add(lblEnterNumbers);
		
		textField = new JTextField();
		textField.setBounds(138, 40, 228, 21);
		frame.getContentPane().add(textField);
		textField.setColumns(10);
		
		JButton btnInsertionSort = new JButton("Insertion Sort");
		btnInsertionSort.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				String str = textField.getText();
				long t,time;
				t = System.currentTimeMillis();
				int[] result = insertionSort(str);
				time = (System.currentTimeMillis() - t);
				textField_2.setText(""+time+" ms ");
				//textField_1.setText(""+result);
				String result1 = "";
				for(int i=0;i<result.length;i++) {
					result1 = result1+" "+result[i];
				}
				textField_1.setText(result1);
			}
			
		});
		btnInsertionSort.setBounds(30, 161, 113, 23);
		frame.getContentPane().add(btnInsertionSort);
		
		JButton btnBubbleSort = new JButton("Bubble Sort");
		btnBubbleSort.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				String str = textField.getText();
				long t,time;
				t = System.currentTimeMillis();
				int[] result = bubbleSort(str);
				time = (System.currentTimeMillis() - t);
				textField_2.setText(""+time+" ms ");
				String result1 = "";
				for(int i=0;i<result.length;i++) {
					result1 = result1+" "+result[i];
				}
				textField_1.setText(result1);
			}
		});
		btnBubbleSort.setBounds(318, 161, 113, 23);
		frame.getContentPane().add(btnBubbleSort);
		
		JButton btnSelectionSort = new JButton("Selection Sort");
		btnSelectionSort.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				String str = textField.getText();
				long t,time;
				t = System.currentTimeMillis();
				int[] result = selectionSort(str);
				time = (System.currentTimeMillis() - t);
				textField_2.setText(""+time+" ms ");
				String result1 = "";
				for(int i=0;i<result.length;i++) {
					result1 = result1+" "+result[i];
				}
				textField_1.setText(result1);
			}
		});
		btnSelectionSort.setBounds(169, 161, 125, 23);
		frame.getContentPane().add(btnSelectionSort);
		
		textField_1 = new JTextField();
		textField_1.setBounds(138, 94, 228, 22);
		frame.getContentPane().add(textField_1);
		textField_1.setColumns(10);
		
		JLabel lblResult = new JLabel("Result");
		lblResult.setBounds(30, 98, 46, 14);
		frame.getContentPane().add(lblResult);
		
		textField_2 = new JTextField();
		textField_2.setBounds(138, 212, 228, 22);
		frame.getContentPane().add(textField_2);
		textField_2.setColumns(10);
		
		JLabel lblTimeTaken = new JLabel("Time Taken");
		lblTimeTaken.setBounds(30, 212, 68, 22);
		frame.getContentPane().add(lblTimeTaken);
	}
	
		public int[] insertionSort(String insert) {
			int[] resultmethod = InsertionSort.InsertionMethod(insert);
			return resultmethod;
		}
		
		public int[] bubbleSort(String insert) {
			int[] resultmethod = BubbleSort.BubbleMethod(insert);
			return resultmethod;
		}
		
		public int[] selectionSort(String insert) {
			int[] resultmethod = SelectionSort.SelectionMethod(insert);
			return resultmethod;
		}
}
